home *** CD-ROM | disk | FTP | other *** search
/ Fantasy Artist 39 / Fantasy Artist - Issue 39.bin / js / panelView.js < prev    next >
Text File  |  2011-08-09  |  2KB  |  70 lines

  1. $(document).ready(function()
  2. {
  3.     var sourceList = $("div.tree > ul");
  4.     
  5.     var issueDiv = document.createElement('div');
  6.     $(issueDiv).addClass('quick_search');
  7.     $(sourceList).parent().after(issueDiv);
  8.     
  9.     var panelView = document.createElement('div');
  10.     $(panelView).addClass('cat_panel');
  11.     $(issueDiv).append(panelView);
  12.     
  13.     $(sourceList).children('li').each(
  14.         function() 
  15.         {
  16.             // Looping through each list item and adding it to
  17.             // the panel div.
  18.             var newLink = document.createElement('a');
  19.             $(panelView).append(newLink);
  20.             $(newLink).html($(this).children('span.cat').text());
  21.         }
  22.     );
  23.  
  24.     $('.cat_panel a').live('click',
  25.         function(e)
  26.         {
  27.             var catSpan = $('div.tree span.cat:contains("'+$(this).text()+'")');
  28.             
  29.             if(catSpan.length > 0)
  30.             {                
  31.                 $(this).parent().nextAll().remove();    
  32.                 // Create a new div
  33.                 
  34.                 var newPanel = document.createElement('div');
  35.                 $(newPanel).addClass('cat_panel');
  36.                 $(this).parent().after($(newPanel));
  37.                 $(newPanel).hide();
  38.     
  39.                 // Find li's from that category
  40.                 var newItems = $(catSpan).parent().children('ul').children('li'); // Three list items
  41.                 
  42.                 $(newItems).each(
  43.                     function()
  44.                     {
  45.                         if ($(this).children('span').length > 0 )
  46.                         {
  47.                             var newLink = document.createElement('a');
  48.                             $(newLink).html($(this).children('span.cat').text());
  49.                             $(newPanel).append($(newLink));
  50.                         }
  51.                         else
  52.                         {
  53.                             var newLink = $(this).clone();
  54.                             $(newPanel).append(newLink);
  55.                         }
  56.                     }
  57.                 );
  58.                 
  59.                 $(newPanel).fadeIn('medium');
  60.                 
  61.                 e.preventDefault();
  62.             }
  63.             else
  64.             {
  65.                 // Leaf node
  66.             }
  67.         }
  68.     );
  69. });
  70.